package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.ui.activity.CreditDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.LoansDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.web.EventWebViewActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.base.Constant;
import com.cardbaobao.cardbabyclient.model.IndexLayout;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

/**
 * Description:
 * Created by FHW
 * on 2017/6/12
 */

public class HotRecyclerAdapter extends CommonRecyclerAdapter<IndexLayout.HomeTabBean> {

    public HotRecyclerAdapter(Context context) {
        super(context, null, R.layout.item_hot_rv);
    }

//    @Override
//    public void onClick(View v, int position, CommonRecyclerHolder holder) {
//        ToastUtil.showToast(getmContext(), position + "");
//    }

    @Override
    public void convert(CommonRecyclerHolder holder, final IndexLayout.HomeTabBean homeTabBean) {
//        holder.setOnClickListener(this, R.id.ll_item);

        holder.setTextViewText(R.id.tv_title, homeTabBean.getTopical());
        holder.setTextViewText(R.id.tv_marketing_one, homeTabBean.getMarketing_one());
        holder.setTextViewText(R.id.tv_marketing_two, homeTabBean.getMarketing_two());

        ImageView iv_pic = holder.getView(R.id.iv_pic);
        ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL + homeTabBean.getPicture_path(), iv_pic);

        LinearLayout ll_item = holder.getView(R.id.ll_item);
        ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent();
                switch (homeTabBean.getPage_type()) {
                    case 0://原生页面
                        switch (homeTabBean.getDetail_code()) {
                            case Constant.ZCC0101://信用卡
                                mIntent.setClass(mContext, CreditDetailActivity.class);
                                mIntent.putExtra(CreditDetailActivity.CARD_ID_S,
                                        homeTabBean.getDetail_id());
                                mIntent.putExtra(CreditDetailActivity.SERIES_CARD_ID_S,
                                        homeTabBean.getDetail_id());
                                mIntent.putExtra(CreditDetailActivity.CARD_NAME_S,
                                        homeTabBean.getTopical());
                                mIntent.putExtra(CreditDetailActivity.FROM_PAGE_S,
                                        "首页");
                                mContext.startActivity(mIntent);
                                break;
                            case Constant.ZCC0102://贷款
                                mIntent.setClass(mContext, LoansDetailActivity.class);
                                mIntent.putExtra(LoansDetailActivity.LOANS_ID_S,
                                        homeTabBean.getDetail_id());
                                mIntent.putExtra(LoansDetailActivity.LOANS_NAME_S,
                                        homeTabBean.getTopical());
                                mIntent.putExtra(LoansDetailActivity.FROM_PAGE_S,
                                        "首页");
                                mContext.startActivity(mIntent);
                                break;
                        }
                        break;
                    case 1://H5页面上传
                    case 2://
                        mIntent.setClass(mContext, EventWebViewActivity.class);
                        mIntent.putExtra("url", homeTabBean.getUrl());
                        mIntent.putExtra(EventWebViewActivity.WEB_TITLE_S, homeTabBean.getTopical());
                        mIntent.putExtra(EventWebViewActivity.WEB_TYPE_I, 7);
                        mContext.startActivity(mIntent);
                        break;
                }
            }
        });
    }

}
